package com.appkubes.mall.restful.application.user.extend.service.impl;

import com.appkubes.mall.core.entity.MallUserExtend;
import com.appkubes.mall.core.service.BaseMallUserExtendService;
import com.appkubes.mall.core.service.impl.BaseMallUserExtendServiceImpl;
import com.appkubes.mall.restful.application.user.extend.service.UserExtendService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: Rongjie
 * @Date: 2020/2/28
 * @Description:
 */
@Service
public class UserExtendServiceImpl extends BaseMallUserExtendServiceImpl implements UserExtendService {
    @Resource
    BaseMallUserExtendService userExtendService;

    @Override
    public Boolean saveClientId(String userKey, String clientId) {
        QueryWrapper<MallUserExtend> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_key", userKey);
        MallUserExtend userExtend = userExtendService.getOne(queryWrapper);
        if (userExtend == null) {
            userExtend = new MallUserExtend();
            userExtend.setUserKey(userKey);
            userExtend.setClientId(clientId);
        } else {
            userExtend.setClientId(clientId);
        }
        return saveOrUpdate(userExtend);
    }
}
